
***Log file
cd "C:\Users\sertsios\Dropbox\LPSU replication package RFS\Replication\Log files\Main Figures"
clear all
log using Fig6.log, replace

***Program for figure
****Figure 6: Dynamics 

***Now extended sample:
cd "C:\Users\sertsios\Dropbox\LPSU replication package RFS\Data"
use LPSU_ExtendedSample_Sep2024, replace
set matsize 10000


***Set of fixed effects
egen sic1year=group(sic1 year)
qui tabulate sic1year, generate(dsic1year)
egen month_post= group(month post)
qui tabulate month_post, generate(dmonth)
qui tabulate year_around_ipo, generate(deventyear)


**Defining event-year x IPO and event-year x instrument
foreach i of num 2/7 {
set more off
gen event_inst`i'=pos_returns*deventyear`i'
gen event_ipo`i'=ipo*deventyear`i'
}

**Create a random variable with mean 0, to include as "benchmark" coefficient of 0 on t=-2. All other event-years will be relative to t=-2
set seed 12345
gen randnum = runiform()
gen randnum2 = runiform()
label var randnum "-2"

**Program to save reduced-form coefficients
capture program drop foo
program foo, eclass
	tempname bmat
    tempname vmat
	matrix `bmat' = e(b)
	matrix `bmat'[1,1] = 0
	matrix `vmat' = e(V)
	matrix `vmat'[1,1] = 0
	ereturn repost b = `bmat'
	ereturn repost V = `vmat'
end

**Label event-years for the instrument
label var event_inst2 "-1" 
label var event_inst3 "0" 
label var event_inst4 "1" 
label var event_inst5 "2" 
label var event_inst6 "3" 
label var event_inst7 "4" 

**Label event-years for IPOs
label var event_ipo2 "-1" 
label var event_ipo3 "0" 
label var event_ipo4 "1" 
label var event_ipo5 "2" 
label var event_ipo6 "3" 
label var event_ipo7 "4" 


**Reduced form regression. Key variables are event-years x positive returns.
set more off
qui xtreg wroa randnum event_inst2 event_inst3 event_inst4 event_inst5 event_inst6 event_inst7 deventyear*  dsic1year* dmonth*, fe cluster(id) 
foo
estimate store RF

set scheme s2color

**RF
coefplot (RF,yline(0) clpattern(shortdash) msymbol(C) msize(large) level(95)),   ///
keep(randnum  event_inst2 event_inst3 event_inst4 event_inst5 event_inst6 event_inst7) /// 
order(randnum  event_inst2 event_inst3 event_inst4 event_inst5 event_inst6 event_inst7) ///
 yline(0)  clpattern(shortdash)  ciopts(recast(rcap) clpattern(shortdash))  ///
 citop vertical  title(OROA reduced-form coefficients)   ///
 xline(2.5, lpattern(dash) lcolor(black)) ysc(r(-0.05 0.05)) ylab(-0.05(0.02)0.05) xtitle(IPO event-years)

graph export "C:\Users\sertsios\Dropbox\LPSU replication package RFS\Figures\Dynamic RF ext.tif", as(tif) replace
 
graph export Fig6A.pdf, replace 
 
**Program to save IV coefficients
capture program drop f2
program f2, eclass
	tempname bmat
    tempname vmat
	matrix `bmat' = e(b)
	matrix `bmat'[1,7] = 0
	matrix `vmat' = e(V)
	matrix `vmat'[7,7] = 0
	ereturn repost b = `bmat'
	ereturn repost V = `vmat'
end 
 
 
**IV regression. Key variables are event-years x IPO. Instruments are event-years x positive returns. 
set more off
qui xtivreg2 wroa randnum (event_ipo2 event_ipo3 event_ipo4 event_ipo5 event_ipo6 event_ipo7 = event_inst2 event_inst3 event_inst4 event_inst5 event_inst6 event_inst7) deventyear* dsic1year* dmonth* ///
, fe cluster(id)  partial(deventyear* dsic1year* dmonth*)
f2
estimate store SS 
 
coefplot (SS,yline(0) clpattern(shortdash) msymbol(C) msize(large) level(95)),   ///
keep(randnum event_ipo2 event_ipo3 event_ipo4 event_ipo5 event_ipo6 event_ipo7) /// 
order(randnum event_ipo2 event_ipo3 event_ipo4 event_ipo5 event_ipo6 event_ipo7) ///
 yline(0)  clpattern(shortdash)  ciopts(recast(rcap) clpattern(shortdash))  ///
 citop vertical  title(OROA second-stage IV coefficients)   ///
 xline(2.5, lpattern(dash) lcolor(black)) ysc(r(-0.5 0.7)) ylab(-0.5(0.2)0.7) xtitle(IPO event-years) 

graph export "C:\Users\sertsios\Dropbox\LPSU replication package RFS\Figures\Dynamic IV ext.tif", as(tif) replace 

graph export Fig6B.pdf, replace  

***Log file
cd "C:\Users\sertsios\Dropbox\LPSU replication package RFS\Replication\Log files\Main Figures"
log close
graphlog using Fig6.log, lspacing(1) replace
